//
//  TLUINavigationViewController.swift
//  TLiOS26LiquidGlassDemo
//
//  Created by jiayin on 2025/7/14.
//

import UIKit

class TLUINavigationViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
//        view.backgroundColor = .white

//        navigationItemSetup();
        barButtonItemSetup();
    }
    
    /**
     UINavigationItem功能介绍：
     1.增加了类型为UIString?的subtitle，用于设置标准模式下的导航栏的副标题。
     2.增加了类型为UIString?的largeTitle与largeSubtitle属性，用于设置 prefersLargeTitles 模式下导航栏的标题与副标题。
     3.增加了类型为UIView?的subtitleView与largeSubtitleView属性，用于设置标准与 prefersLargeTitles 模式下导航栏的副标题视图。
     */
    private func navigationItemSetup() {
        navigationController?.navigationBar.prefersLargeTitles = true
        // iOS26新增
        navigationItem.largeTitle = "导航"
        navigationItem.largeSubtitle = "子标题"
    }
    
    /**
     UIBarButtonItem功能介绍：
     1.增加了badge属性，用于设置角标。
     2.增加了prominent样式，用于凸显。
     3.增加了fixedSpace()与flexibleSpace()方法，用于调整彼此之间的间距。
     */
    private func barButtonItemSetup() {
        view.backgroundColor = .systemGreen

        let barButtonItems = [
            UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(handleEvent)),
            UIBarButtonItem(barButtonSystemItem: .bookmarks, target: self, action: #selector(handleEvent)),
            UIBarButtonItem(barButtonSystemItem: .camera, target: self, action: #selector(handleEvent)),
            UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(handleEvent))
        ]
        
        barButtonItems[0].badge = .count(10)
        barButtonItems[3].style = .prominent
        
        let fixedSpace = UIBarButtonItem.fixedSpace(20)
        let flexibleSpace = UIBarButtonItem.flexibleSpace()
        
        navigationItem.rightBarButtonItems = [barButtonItems[0]]
        navigationController?.isToolbarHidden = false
        toolbarItems = [barButtonItems[1], fixedSpace, barButtonItems[2], flexibleSpace, barButtonItems[3]]
    }
    
    @objc func handleEvent(_ sender: UIBarButtonItem) {
        view.backgroundColor = .init(red: .random(in: 0 ... 1), green: .random(in: 0 ... 1), blue: .random(in: 0 ... 1), alpha: 1.0)
    }
    
}
